package com.flute.framework.data.mysql;

import java.util.List;

import org.amino.ds.lockfree.LockFreeList;
import org.apache.commons.lang.StringUtils;

import com.flute.framework.data.constants.Constants;

public final class OrderBySQL{
	private List<String> orderByClauses;

	public void addOrderByClause(String orderClause) {
		if (orderByClauses == null) {
			orderByClauses = new LockFreeList<String>();
		}
		if (!orderByClauses.contains(orderClause)) {
			orderByClauses.add(orderClause);
		}
	}

	public String toSQL() {
		if (orderByClauses == null || orderByClauses.isEmpty()) {
			return Constants.EMPTY;
		}
		return Constants.ORDER_BY + StringUtils.join(orderByClauses, ",");
	}
}
